/**
 * author: Keil
 * description: 倾小瘦健康管理小程序
 * @createTime: 2022-07-21 16:55:10
 */
import App from './App'
// #ifndef VUE3
import Vue from 'vue'

import request from '@/common/api/request.js'
import store from './store'
Vue.prototype.request = request
import myEmpty from "@/components/empty/empty.vue"
Vue.component('myEmpty', myEmpty)
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
uni.$u.setConfig({
	config: {
		unit: 'rpx'
	}
})

let Helper = {
	paste(value) {
		uni.setClipboardData({
			data: value,
			success: () => {
				uni.showToast({
					title: "已复制分享连接",
					icon: 'none'
				})
			}
		})
	},
	showLoading(title) {
		uni.showLoading({
			title: title || '加载中'
		})
	},
	showToast(title, icon) {
		uni.showToast({
			title: title || '提示',
			icon: icon || 'none'

		})
	},

	navigateTo(url) {
		uni.navigateTo({
			url: url
		})
	},
	reLaunch(url) {
		uni.reLaunch({
			url: url
		})
	},
	redirectTo(url) {
		uni.redirectTo({
			url: url
		})
	},
	switchTab(url) {
		uni.switchTab({
			url: url
		})
	},
	formatDate(date) {
		var myyear = date.getFullYear();
		var mymonth = date.getMonth() + 1;
		var myweekday = date.getDate();
		if (mymonth < 10) {
			mymonth = "0" + mymonth;
		}
		if (myweekday < 10) {
			myweekday = "0" + myweekday;
		}
		return (myyear + "-" + mymonth + "-" + myweekday);
	},
	getWeeksByYear(year) {
		var startTime = new Date();
		startTime.setFullYear(year);
		startTime.setMonth(0)
		startTime.setDate(1);
		startTime.setHours(12);
		var endTime = new Date();
		endTime.setFullYear(year);
		endTime.setMonth(11)
		endTime.setDate(31);
		endTime.setHours(12);
		var dayTime = 1000 * 60 * 60 * 24;
		var days = (endTime.getTime() - startTime.getTime()) / dayTime + 1
		var week = [];
		var weekes = [];
		for (var i = 0; i < days; i++) {
			var date = new Date();
			date.setTime(startTime.getTime() + i * dayTime);
			var monthStr = (date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1)
			var dayStr = (date.getDate()) < 10 ? ("0" + (date.getDate())) : (date.getDate())
			var dateStr = (date.getFullYear()) + "-" + (monthStr) + "-" + dayStr;
			var dayweek = date.getDay() === 0 ? 7 : date.getDay();
			if (dayweek == 1) {
				weekes.push(JSON.parse(JSON.stringify(week)));
				week = [];
				week[dayweek - 1] = dateStr;
			} else {
				week[dayweek - 1] = dateStr;
			}
		}
		if (week.length != 0) {
			weekes.push(week);
		}
		return weekes;
	},
	filterSpace(string) {
		const reg = /^\s+$/g;
		return reg.test(string);
	},
}

Vue.prototype.helper = Helper;
Vue.prototype.imgURL = Helper.imgURL;
Vue.config.productionTip = false
Vue.filter('toFixed',(value,step=10,fractionDigits=1)=>(value/step).toFixed(fractionDigits))
App.mpType = 'app'
const app = new Vue({
	...App,
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
